In previous tutorial, you created a directory called ~/src/cslim and under that is CppUTest. To create this project, we'll use the equivalent of environment variables in Eclipse.
Create a new workspace. Select the directory containing two github projects you just checked out. In my case that's Users/schuchert/src/waat/workspace
Close the Welcome to Eclipse tab.
Edit the Eclipse properties:
Under General:Workspce, enable Refresh automatically
Under Eclipse properties:C/C++:Build:Environment, define some environment variables:
Since you've already worked through Getting Started With FitNesse in C++, you have FitNesse installed somewhere. Start your FitNesse instance. Here's what it looks like on my computer:
[~]% cd src/cpp_fitnesse
/Users/schuchert/src/cpp_fitnesse
[~/src/cpp_fitnesse]% java -jar fitnesse.jar -p 8080
FitNesse (v20100711) Started...
port: 8080
root page: fitnesse.wiki.FileSystemPage at ./FitNesseRoot
logger: none
authenticator: fitnesse.authentication.PromiscuousAuthenticator
html page factory: fitnesse.html.HtmlPageFactory
page version expiration set to 14 days.
Creating Top-Level Test Suite
Now that you have FitNesse started, create a top-level page for all of your work.
This project is neither a test or suite page by default (it has to do with the page's name). So click on its Properties button, select the Test radio button and then click on Save Properties
This page makes reference to a fixture that does not yet exist. As in the previous step, don't worry. That's next.
Creating Fixture Project
Now you're going to add a third project to contain your fixtures. This involves creating a project, linking to the calculator.
Select File:New:C++ Project
Create an Empty Project
Under Toolchains either select Mingw or some other "working" toolchain. As of this writing, the cygwin will work but you cannot use a debugger.
For the project name, enter RpnCalculatorFixtures, which you can infer from the TEST_SYSTEM variable set on the top-level page.
The provided code uses features of G++ 4.4 and above, specifically the compiler flag-std=c++0x. The primary thing is the use of the standard class shared_ptr. As of the TR1 standard, this class' namespace is std::tr1::. In the upcoming standard, the class is additionally in std::. To fix this, edit the project's properties. Under C/C++ Build:Settings/C++ Compiler: Miscellaneous, add -std=c++0x (that's zero, not o) to the Other flags.
You'll need to copy in two boilerplate files, create the fixture class and then set up libraries and include paths.
Add a new file called Main.c and set its contents:
You'll notice a few more warnings about unknown include files. You'll add a few more include directories, this time under the C++ tab instead of the C Tab
Edit the project's properties
Select C/C++ Build:Settings
Now select GCC C++ Compiler (or similar) and under Includes add: ${workspace_loc:/RpnCalculatorInCpp} "${CSLIM_BASE}/include/CSlim"
Apply those changes.
Notice that there's still one missing header file. This is in another library that I've written to make writing C++ cslim fixtures a bit easer:
Go back to your workspace directory
Clone the CSlimCppExtensions project from github with the following command:
There should be one project listed, CSlimCppExtensions
Click on Finish
Select the project, right-click and select build.
Warning: As of this writing, there is a "missing" method in the cslim library. You'll need to make two changes to the cslim library that you've downloaded to resolve this.
Updating CSlim Library
<cslim_base>/include/CSlim/SlimListSerializer.h
Add the following function declaration to the header file:
void SlimList_Release(char*serializedList);
<cslim_base>/src/CSlim/SlimListSerializer.h
Add a function declaration to the source file:
Now that you have the required missing project, you need to add it as a dependent project and include its header files in the RpnCalcualtorFixtures project:
Edit the properties of RpnCalculatorFixtures
Under the top-level Project References, select CSlimCppExtensions
Under C/C++ Build:Settings, select the C++ Compiler settings
Add under include the following directory: ${workspace_loc:/CSlimCppExtensions}
Now if you try to build the project, it will compile but it will not link.
Edit the project's settings
Find the linker settings under C/C++ Build:Linker
Edit the Libraries and add the following list: CSlim RpnCalculatorInCpp CppUTest CSlimCppExtensions
Edit he Library search path and add the following list: ${workspace_loc:/RpnCalculatorInCpp/Debug} ${CSLIM_BASE}/lib ${CPPUTEST_BASE}/lib ${workspace_loc:/CSlimCppExtensions/Debug}
Save your changes and build again
You should now be able to run this executable. If you do, you'll see in red text:
getaddrinfo: nodename nor servname provided, or not known
Running the Test
You should be able to run your FitNesse test and get to green.
You might see an error regarding a difference in protocol. That's under construction. The cslim library should be updated in the near future (August 2010 I hope).
Working with a Script Table
Now it is time to program the calculator. First a test, then the fixture code.
Table of Contents
Background
These steps assuem you have already worked through the tutorial: Getting Started With FitNesse in C++.Building the RpnCalcualtor
You can find the source for the RpnCalculator at two github locations:Building the Basic Structure
Configuring the Eclipse Project
In previous tutorial, you created a directory called ~/src/cslim and under that is CppUTest. To create this project, we'll use the equivalent of environment variables in Eclipse.Under General:Workspce, enable Refresh automatically
Under Eclipse properties:C/C++:Build:Environment, define some environment variables:
- CSLIM_BASE = /Users/schuchert/src/cslim/cslim
- CPPUTEST_BASE = /Users/schuchert/src/cslim/cpputest
On my Mac, I additionally set:- GPP = /usr/local/bin/g++
This allows me to use g++ 4.4 or 4.5 instead of 4.2RpnCalculatorInCpp
RpnCalculatorInCppTests
You should see your tests pass. As of this writing, there are 70 tests:
Creating Your First Test Table
Since you've already worked through Getting Started With FitNesse in C++, you have FitNesse installed somewhere. Start your FitNesse instance. Here's what it looks like on my computer:[~]% cd src/cpp_fitnesse /Users/schuchert/src/cpp_fitnesse [~/src/cpp_fitnesse]% java -jar fitnesse.jar -p 8080 FitNesse (v20100711) Started... port: 8080 root page: fitnesse.wiki.FileSystemPage at ./FitNesseRoot logger: none authenticator: fitnesse.authentication.PromiscuousAuthenticator html page factory: fitnesse.html.HtmlPageFactory page version expiration set to 14 days.Creating Top-Level Test Suite
Now that you have FitNesse started, create a top-level page for all of your work.!contents -R2 -g -p -f -h !define TEST_SYSTEM {slim} !define TEST_RUNNER {/Users/schuchert/src/waat/workspace/RpnCalculatorFixtures/Debug/RpnCalculatorFixtures} !define COMMAND_PATTERN {%m}The TEST_RUNNER makes reference to a project/executable we have not yet created. Don't worry, it'll be there soon.
Creating First Test
This page makes reference to a fixture that does not yet exist. As in the previous step, don't worry. That's next.
Creating Fixture Project
Now you're going to add a third project to contain your fixtures. This involves creating a project, linking to the calculator.- Select File:New:C++ Project
- Create an Empty Project
- Under Toolchains either select Mingw or some other "working" toolchain. As of this writing, the cygwin will work but you cannot use a debugger.
- For the project name, enter RpnCalculatorFixtures, which you can infer from the TEST_SYSTEM variable set on the top-level page.
- The provided code uses features of G++ 4.4 and above, specifically the compiler flag -std=c++0x. The primary thing is the use of the standard class shared_ptr. As of the TR1 standard, this class' namespace is std::tr1::. In the upcoming standard, the class is additionally in std::. To fix this, edit the project's properties. Under C/C++ Build:Settings/C++ Compiler: Miscellaneous, add -std=c++0x (that's zero, not o) to the Other flags.
You'll need to copy in two boilerplate files, create the fixture class and then set up libraries and include paths.You'll notice several warnings about unknown header files. Let's fix that before moving on:
"${CSLIM_BASE}/include/CSlim"
"${CSLIM_BASE}/include/Com"
Next, create another new file called Fixtures.c:
I'm having you preemptively add in the name of a fixture you have yet to write.
Now it's time to create the fixture. Since this is a mechanics tutorial, I'll give you the fixture source code:
ExecuteBinaryOperator.cpp
You'll notice a few more warnings about unknown include files. You'll add a few more include directories, this time under the C++ tab instead of the C Tab
${workspace_loc:/RpnCalculatorInCpp}
"${CSLIM_BASE}/include/CSlim"
Notice that there's still one missing header file. This is in another library that I've written to make writing C++ cslim fixtures a bit easer:
Updating CSlim Library
<cslim_base>/include/CSlim/SlimListSerializer.hAdd the following function declaration to the header file:
<cslim_base>/src/CSlim/SlimListSerializer.h
Add a function declaration to the source file:
Now that you have the required missing project, you need to add it as a dependent project and include its header files in the RpnCalcualtorFixtures project:
Now if you try to build the project, it will compile but it will not link.
CSlim
RpnCalculatorInCpp
CppUTest
CSlimCppExtensions
${workspace_loc:/RpnCalculatorInCpp/Debug}
${CSLIM_BASE}/lib
${CPPUTEST_BASE}/lib
${workspace_loc:/CSlimCppExtensions/Debug}
You should now be able to run this executable. If you do, you'll see in red text:
Running the Test
You should be able to run your FitNesse test and get to green.Working with a Script Table
Now it is time to program the calculator. First a test, then the fixture code.The Test
Create the following test at: http://localhost:8080/RpnExamples.SumOfPrimesExampleThis creates a new operator called "sumOfPrimesFactors" and then executes it. To make this work, you'll need to create a new fixture and register it.
Creating the Fixture
Create a new source filed called ProgramTheCalcualtor.cpp. Here's the source:To get this working, you'll need to register the fixture by updated Fixtures.c:
Once you make these changes and rebuild, you should have a passing test.
The Query Table
Here is an example of a query table:Create this page at: http://localhost:8080/RpnExamples.AlphaNamedOperatorsExample
Now you'll need to create a fixture. Create a new source file called AlphaNamedOperators.cpp:
To get this registered, you'll have to update Fixtures.c:
Save and rebuild. You should now have a passing test. If you run the entire suite, all three tests should pass.
<--Back